/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gray.swing.field;

import java.awt.Container;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import gray.Field;
import snippet.Snipet;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import javax.swing.JLabel;

/**
 *
 * @author martin
 */
public class ComboField extends JPanel implements Field<String,Container>{
    private final JComboBox cb;
    private ComboField(final Snipet lang,final String name, final String [] lst, final Character key){
        super(new FlowLayout(FlowLayout.RIGHT));
        cb = new JComboBox(lst);
        cb.setSelectedIndex(1);
        JLabel label = new JLabel(name);
                             
        label.setDisplayedMnemonic(KeyEvent.getExtendedKeyCodeForChar(key));
        label.setLabelFor(cb);
        
        add(label);
        add(cb);

    }
    
    public static Field<String,Container> factory(final Snipet lang,final String name, final String [] lst, final Character key){
        return new ComboField(lang, name,lst,key);
    }
    
    
    @Override
    public String input() {
        return (String)cb.getSelectedItem();
    }

    @Override
    public Container container() {
        return this;
    }

    @Override
    public Boolean ready() {
        return true;
    }
}
